'use strict';
const db = uniCloud.database();
const roomsCollection = db.collection('rooms');

exports.main = async (event, context) => {
	const { floor_id } = event;
	
	// 参数校验
	if (!floor_id) {
		return {
			code: 1,
			message: '缺少楼层ID参数'
		};
	}
	
	// 根据楼层ID获取房间列表
	const { data: rooms } = await roomsCollection
		.where({
			floor_id: floor_id
		})
		.orderBy('room_number', 'asc')
		.get();
	
	return {
		code: 0,
		message: '获取房间列表成功',
		data: rooms
	};
}; 